package com.itgone.view.activity;

import android.support.v4.view.ViewPager;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.TextView;

import com.itgone.R;
import com.itgone.presenter.IProductDetailPresenter;
import com.itgone.presenter.impl.ProductDetailPresenterImpl;
import com.itgone.view.IProductDetailView;
import com.itgone.view.adapter.ProductImageVPAdapter;

public class ProductDetailActivity extends BaseActivity implements IProductDetailView {


    private WebView mVvDetail;
    private ViewPager mVpMainImg;

    private TextView mTvPrice, mTvSubtitle, mTvName;

    @Override
    int getLayoutId() {
        return R.layout.activity_product_detail;
    }

    @Override
    protected void initView() {
        setTitle("商品详情");

        mVvDetail = findViewById(R.id.wv_product_detail);
        WebSettings webSettings = mVvDetail.getSettings();
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);//把html中的内容放大webview等宽的一列中
        webSettings.setJavaScriptEnabled(true);//支持js

        mVpMainImg = findViewById(R.id.vp_product_main_img);

        mTvPrice = findViewById(R.id.tv_product_price);
        mTvSubtitle = findViewById(R.id.tv_product_subtitle);
        mTvName = findViewById(R.id.tv_product_name);
    }

    @Override
    protected void initData() {
        IProductDetailPresenter productDetailPresenter = new ProductDetailPresenterImpl(this);
        productDetailPresenter.loadProductDetail();
    }


    @Override
    public void loadWebView(String htmlStr) {
        mVvDetail.loadData(htmlStr, "text/html", "utf-8");
    }

    @Override
    public void loadViewPage(String[] imgUrlArr) {
        mVpMainImg.setAdapter(new ProductImageVPAdapter(this, imgUrlArr));
    }

    @Override
    public void setName(String name) {
        this.mTvName.setText(name);
    }

    @Override
    public void setPrice(double price) {
        this.mTvPrice.setText("￥" + price);
    }

    @Override
    public void setSubtitle(String subtitle) {
        this.mTvSubtitle.setText(subtitle);
    }
}
